<script setup lang="ts">
import weblogo from "~/assets/web-logo.png"
import { useUserStore } from "~/store/useUser";
import { ElMessage } from "element-plus";

const defaultProps = defineProps({
	bgColor: {
		type: String,
		default: 'none'
	}
})

const router = useRouter()
const userStore = useUserStore()

const toLogin = ()=>{
	router.push('/login')
}

const toSellerCenter = () => {
	// 检查用户是否已登录
	if (!userStore.isLogin) {
		// ElMessage.warning('请先登录后再进入卖家中心');
		router.push({
			path: '/login',
			query: { redirect: '/sellerRegistration' }
		});
		return;
	}
	
	// 跳转到内部的卖家注册页面，而不是外部链接
	navigateTo('/sellerRegistration');
};
</script>

<template>
	<div class="menu-box" :style="{background: defaultProps.bgColor}">
		<div class="header-menu">
			<h1 class="logo" title="技能猴子">
				<nuxt-link to="/"><img :src="weblogo" alt="技能猴子"></nuxt-link>
			</h1>
			<div class="menus">
				<div class="menu-list" >
					<nuxt-link class="active" to="/">首页</nuxt-link>
					<nuxt-link to="/commodity">商品</nuxt-link>
					<nuxt-link>猴子素材</nuxt-link>
					<nuxt-link>企业雇佣</nuxt-link>
					<nuxt-link>效率工具</nuxt-link>
					<nuxt-link to="/sellerRegistration">卖家入驻</nuxt-link>
					<nuxt-link to="/companyAccount">企业账户</nuxt-link>
					<nuxt-link to="/news">技能头条</nuxt-link>
					<nuxt-link to="/appDownload">下载APP</nuxt-link>
				</div>
				<div class="btns">
					<button class="seller-central" @click="toSellerCenter">卖家中心</button>
					<button class="login-reg" @click="toLogin">登录/注册</button>
				</div>
			</div>
		</div>
	</div>
</template>

<style scoped lang="scss">
.menu-box {
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 80px;
	z-index: 100;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0 20px;
	box-sizing: border-box;
	
	@media (max-width: 768px) {
		height: 60px;
		padding: 0 16px;
	}
	
	@media (max-width: 480px) {
		height: 56px;
		padding: 0 12px;
	}
}

.header-menu {
	width: 100%;
	max-width: 1200px;
	height: 80px;
	display: flex;
	align-items: center;
	
	@media (max-width: 768px) {
		height: 60px;
	}
	
	@media (max-width: 480px) {
		height: 56px;
	}
}

.logo {
	flex: 1;
	height: 40px;
	display: flex;
	align-items: center;
	
	@media (max-width: 768px) {
		height: 32px;
	}
	
	@media (max-width: 480px) {
		height: 28px;
	}
	
	a {
		height: 40px;
		
		@media (max-width: 768px) {
			height: 32px;
		}
		
		@media (max-width: 480px) {
			height: 28px;
		}
	}
	
	img {
		width: 118px;
		height: 40px;
		
		@media (max-width: 768px) {
			width: 94px;
			height: 32px;
		}
		
		@media (max-width: 480px) {
			width: 82px;
			height: 28px;
		}
	}
}

.menus {
	display: flex;
	align-items: center;
	
	@media (max-width: 768px) {
		.menu-list {
			display: none;
		}
	}
	
	.menu-list {
		@media (max-width: 1024px) {
			a {
				padding: 0 8px;
				font-size: 14px;
			}
		}
		
		a {
			padding: 0 15px;
			cursor: pointer;
			text-decoration: none;
			color: rgba(255, 255, 255, 0.48);
			white-space: nowrap;
			
			&.active {
				color: #fff;
			}
			
			&:hover {
				color: #fff;
			}
		}
	}
	
	.btns {
		display: flex;
		align-items: center;
		gap: 15px;
		
		@media (max-width: 480px) {
			gap: 8px;
		}
		
		button {
			font-size: 12px;
			cursor: pointer;
			white-space: nowrap;
			
			@media (max-width: 480px) {
				font-size: 11px;
				padding: 0 8px;
			}
		}
		
		.seller-central {
			background: none;
			border-radius: 8px;
			width: 86px;
			height: 36px;
			border: 1px solid #ffffff;
			color: #fff;
			
			@media (max-width: 480px) {
				width: 70px;
				height: 32px;
				border-radius: 6px;
			}
		}
		
		.login-reg {
			background: #1dbf73;
			border-radius: 8px;
			width: 86px;
			height: 36px;
			border: 1px solid #1dbf73;
			color: #fff;
			
			@media (max-width: 480px) {
				width: 70px;
				height: 32px;
				border-radius: 6px;
			}
		}
	}
}

// 平板适配
@media (min-width: 769px) and (max-width: 1024px) {
	.header-menu {
		max-width: 100%;
		padding: 0 20px;
	}
}

// 大屏幕适配
@media (min-width: 1200px) {
	.header-menu {
		max-width: 1400px;
	}
}
</style>